import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Play {
    List<Card> box=new ArrayList<>(54);
    public void start(){
        prepare();
        publish();
        show();
//        for (Card card:box){
//            System.out.println(card);
//        }
    }
    private void show(){
        p1.showCards();
        p2.showCards();
        p3.showCards();
    }
    private Player p1,p2,p3;
    private  void publish(){
        p1=new Player(("jOhn"));
        p2=new Player(("Jane"));
        p3=new Player(("Bob"));

        for(int i=0;i<54;i++){
          int pos=new Random().nextInt(box.size());//0-53
          Card get=box.remove(pos);//拿到并且删除一张牌
           int which=i%3;//求得哪一个玩家要收取这张牌
           switch (which){
               case 0:
                   p1.receiveCard(get);
                   break;
               case 1:
                   p2.receiveCard(get);
                   break;
               default:
                   p3.receiveCard(get);
           }

        }
    }
    private  void prepare(){
        for(int i=1;i<14;i++){
         String str_num=String.valueOf(i);
         int t_num=i;

         switch (i){
             case 1:
                 str_num="A";
                 t_num=14;
                 break;
             case 2:
                 t_num=15;
                 break;
             case 11:
                 str_num="J";
                 break;
             case 12:
                 str_num="0";
                 break;
             case 13:
                 str_num="K";
                 break;
         }


         Card c1=create("♥",str_num, t_num );
         Card c2=create("♣",str_num, t_num );
         Card c3=create("♦",str_num, t_num );
         Card c4=create("♠",str_num, t_num );
         box.add(c1);
         box.add(c2);
         box.add(c3);
         box.add(c4);
        }
        box.add(create("joke",null,88));
        box.add(create("JOKE",null,888));

    }
    private Card create(String pattren,String str_num,int t_size){
    Card c =new Card();
    c.setPattern(pattren);
    c.setStr_num(str_num);
    c.setT_size(t_size);
     return c;
    }


}
